using UnityEngine;
using System.Collections;

public class AOEBlastScript : MonoBehaviour {
    public float life = 0.0f;
    public float channel = 1.0f;
    public float duration = 3.0f;
    public float damage = 20.0f;
    
    private float currentRotation = 0.0f;
    private Vector3 radius = new Vector3(15,0,0);
    private Quaternion rotation;
    private Vector3 temp;
    
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        life += Time.deltaTime;
        if (life >= (duration + channel)){
            GameObject.Destroy(gameObject);
        }
        
        // channeling spell, don't do anything
        if (life < channel)
            return;
        
        currentRotation += Time.deltaTime*1000;
        rotation.eulerAngles = new Vector3(0, currentRotation, 0);
        transform.position = transform.parent.position;
        temp = rotation * radius;
        transform.position += temp;
        
    }
    
    void OnTriggerEnter(Collider other){
        // don't kill anything while it's channeling
        if (life <= channel)
            return;
            
        EnemyHealth e = other.GetComponent<EnemyHealth>();
        if(e != null){
            e.damage(damage);
        }
        
        PlayerHealth p = other.GetComponent<PlayerHealth>();
        if(p != null){
            p.damage(damage);
        }
    }
}